package com.example.rentalclearing.entity;

import com.baomidou.mybatisplus.annotation.*;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.io.Serializable;

@Data
@TableName("bank_collection_record")
@Schema(description = "银行收款记录")
public class BankCollectionRecord implements Serializable {

    @TableId(type = IdType.AUTO)
    @Schema(description = "主键ID")
    private Long id;

    @Schema(description = "付款账户名称")
    private String payerAccountName;

    @Schema(description = "付款银行名称")
    private String payerBankName;

    @Schema(description = "付款卡号（可脱敏存储）")
    private String payerCardNumber;

    @Schema(description = "付款金额")
    private BigDecimal paymentAmount;

    @Schema(description = "付款日期")
    private LocalDate paymentDate;

    @Schema(description = "付款时间（精确到时分秒）")
    private LocalTime paymentTime;

    @TableField(fill = FieldFill.INSERT)
    @Schema(description = "已使用金额（用于关联核销租金等）")
    private BigDecimal amountUsed = BigDecimal.ZERO;

    @Schema(description = "使用状态：未使用(unused)，部分使用(partially_used)，已使用(fully_used)")
    private String usageStatus; // unused, partially_used, fully_used

    @TableField(fill = FieldFill.INSERT)
    @Schema(description = "创建时间")
    private LocalDateTime createdAt;

    @TableField(fill = FieldFill.INSERT_UPDATE)
    @Schema(description = "最后更新时间")
    private LocalDateTime updatedAt;

/*    @TableField(exist = false)
    @Schema(description = "内存中使用：未核销金额")
    private BigDecimal availableAmount; // 内存中使用：未核销金额*/

    /**
     * 获取未核销金额(付款金额减已使用金额)
     * @return
     */
    public BigDecimal getAvailableAmount() {
        return this.paymentAmount.subtract(this.amountUsed);
    }
}
